package WebFinder

import (
	"gitee.com/fierce_wolf/go-web-crawler/WebCrawler"
)

type ElTag struct {
	List  []*WebCrawler.WebElement // 电子邮箱的相关元素，其中text字段被识别为电子邮箱
	Param string
}

func (e *ElTag) GetList() []*WebCrawler.WebElement {
	return e.List
}

func (e *ElTag) Find(els []*WebCrawler.WebElement) []*WebCrawler.WebElement {
	e.List = make([]*WebCrawler.WebElement, 0)

	els = WebCrawler.Site.FindElements(els, WebCrawler.Filter{
		Mode:  WebCrawler.ModeElTag,
		Param: e.Param,
	})

	originals := make([]*WebCrawler.WebElement, 0)
	for _, el := range els {
		// 原本
		originals = append(originals, el)

		// 副本
		clone := el.Clone()
		e.List = append(e.List, clone)
	}

	return originals
}
